{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e3e2c219-7fc7-4593-8d87-27fdba441fc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "546455de-2079-4847-9a03-9807852eb843",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f2ad6d5f-d0db-41cf-a98e-de51c8f561cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构造转换器\n",
    "converter = tf.lite.TFLiteConverter.from_saved_model('./data/face_mask_model/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e3abc7a1-bf94-4949-92d7-6cd4830e1a14",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 转换\n",
    "tflite_model = converter.convert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4593e78d-29e1-4208-bb3e-2fa870aa5969",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 保存lite\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d6f3dc8c-f5be-4fab-a724-44c6fa6f61ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('./data/face_mask.tflite','wb') as f:\n",
    "    f.write(tflite_model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f32c7561-b977-49c6-a6da-beab81b900ed",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
